package com.newgrand.ng5.service.Impl;

import com.newgrand.ng5.dao.entity.User;
import com.newgrand.ng5.dao.mapper.EmployeeMapper;
import com.newgrand.ng5.dao.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author ：minyang
 * @date ：Created in 2019/8/19 7:20
 */
public class TestSqlInjectorServiceImpl {

    @Autowired
    EmployeeMapper employeeMapper;

    @Autowired
    UserMapper userMapper;

    /**
     * 测试Oracle 主键 Sequence
     */
    public void testOracle() {
        User user = new User();
        user.setLogicFlag(1);
        user.setName("OracleSEQ");
        userMapper.insert(user);
    }

    /**
     * 测试公共字段填充
     */
    public void testMetaObjectHandler() {
        User user = new User();
        //user.setName("Tom");

        user.setId(5);
        user.setLogicFlag(1);

        userMapper.updateById(user);
    }

    /**
     * 测试逻辑删除
     */
    public void testLogicDelete() {

        Integer result = userMapper.deleteById(1);
        System.out.println("result:" + result);

        User user = userMapper.selectById(1);
        System.out.println(user);
    }


    /**
     * 测试自定义全局操作
     */
    public void testMySqlInjector() {
        Integer result = employeeMapper.deleteAll();
        System.out.println("result: " + result);
    }
}
